-
Notifications
You must be signed in to change notification settings - Fork 754
hooks: Add support for running jj fix as a pre-upload hook.
#7801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
2d9fb18 to
5e574e4
Compare
5e574e4 to
38f4ab3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor stuff, I also don't really agree with how the code currently was rewritten but I'm unable to point at it.
cc @hooper
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: In the commit description you could mention that "you" (i.e the chromium project) scripted around that which is imo a good motivation.
| /// Currently, this triggers on `jj gerrit upload`. Other forges which | ||
| /// implement custom upload scripts should also call this. | ||
| /// | ||
| /// This should ideally work for `jj git push` too, but doing so has | ||
| /// consequences. `git push` can be used to upload to code review, but it can | ||
| /// do many other things as well. We need to ensure the UX works well before | ||
| /// adding it to `git push`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should advertise this as "general hook" support. Since it is the only support we'll ever have
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intend to add support for general hooks in the future. This is why I'm working on repo-managed config. Having that will allow us to do this in a secure manner.
|
We already have some "on push" behavior, namely signing. I had an old diff I never upstreamed that added a new flag called diff --git a/cli/src/commands/git/push.rs b/cli/src/commands/git/push.rs
index 88403257ea..fee554e83b 100644
--- a/cli/src/commands/git/push.rs
+++ b/cli/src/commands/git/push.rs
@@ -393,7 +393,7 @@
return Ok(());
}
- let sign_behavior = if tx.settings().get_bool("git.sign-on-push")? {
+ let sign_behavior = if should_sign_on_push(tx.settings())? {
Some(SignBehavior::Own)
} else {
None
@@ -1016,3 +1016,15 @@
.collect_vec();
Ok(bookmarks_targeted)
}
+
+fn should_sign_on_push(settings: &UserSettings) -> Result<bool, CommandError> {
+ // First check the new on-push-behavior configuration
+ if let Ok(behaviors) = settings.get::<Vec<String>>("git.on-push-behavior") {
+ return Ok(behaviors.contains(&"sign".to_string()));
+ } else if let Some(behavior) = settings.get_string("git.on-push-behavior").optional()? {
+ return Ok(behavior == "sign");
+ }
+
+ // Fall back to the old sign-on-push configuration for backward compatibility
+ settings.get_bool("git.sign-on-push").map_err(Into::into)
+}
diff --git a/cli/src/config-schema.json b/cli/src/config-schema.json
index e4ed1a4c81..da11add710 100644
--- a/cli/src/config-schema.json
+++ b/cli/src/config-schema.json
@@ -468,6 +468,22 @@
"description": "Whether jj should sign commits before pushing",
"default": false
},
+ "on-push-behavior": {
+ "description": "List of behaviors to execute before pushing",
+ "oneOf": [
+ {
+ "type": "string",
+ "enum": ["sign"]
+ },
+ {
+ "type": "array",
+ "items": {
+ "type": "string",
+ "enum": ["sign"]
+ }
+ }
+ ]
+ },
"track-default-bookmark-on-clone": {
"type": "boolean",
"description": "Whether `jj git clone` creates a local bookmark tracking the default remote bookmark",I had then wanted to extend FWIW, I'm not so sure about special casing it only on |
I agree but ideally we really shouldn't run untrusted programs but should use user-aliases instead. This will let users plug a bunch of with the model. And matching on bookmark patterns also makes sense. |
I have a follow-up PR that adds support for generalized hooks rather than just supporting fix. I don't like having it as a list though, since that introduces several UX issues:
I believe that an approach such as what My intent was to have specifically
This is one of the reasons I'm working on secure configuration and secure repo configuration. I intend to do something similar to fix tools in the future, which should make this secure. |
We will support arbitrary hooks in the future, but for a few reasons we will special-case `jj fix`: * Performance (jj fix is hyper-optimized for running on stacks of commits at the same time) * Common (This will probably be the most common requested pre-upload check) * Simplicity (this was much easier to implement, so is a good first hook) Bug: jj-vcs#3577
38f4ab3 to
9fc5a68
Compare
We will support arbitrary hooks in the future, but for a few reasons we will special-case
jj fix:Bug: #3577
Checklist
If applicable:
CHANGELOG.mdREADME.md,docs/,demos/)cli/src/config-schema.json)